﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ASMS.Excel2DbTool.Utils
{
    public class 仓库数据20170208
    {
        public static void Run(string filePath, string destFileName)
        {
            DataTable dataTable = Sunboxsoft.Excel.ReadTool.ReadExcel(filePath, true);

            StringBuilder coordJsonBuilder = new StringBuilder("{");
            StringBuilder projectJsonBuilder = new StringBuilder("[");

            List<string> projectList = new List<string>();
            List<string> projectLinkList = new List<string>();
            List<string> deptList = new List<string>();
            for (int index = 0; index < dataTable.Rows.Count; index++)
            {
                string capacityString = Convert.ToString(dataTable.Rows[index][8]).Trim();
                string city = Convert.ToString(dataTable.Rows[index][10]).Trim();

                if (string.IsNullOrEmpty(city)
                    || string.IsNullOrEmpty(capacityString))
                    continue;

                decimal capacity = 0.0m;
                if (!decimal.TryParse(capacityString, out capacity))
                {
                    continue;
                }

            }
            projectJsonBuilder.Append("]");
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat("{{\"coordMap\":{0},\"links\":{1}}}", coordJsonBuilder, projectJsonBuilder);

            string destFilePath = string.Format("{0}\\{1}", AppDomain.CurrentDomain.BaseDirectory, destFileName);
            System.IO.File.WriteAllText(destFilePath, builder.ToString());
            Console.WriteLine(string.Format("转换完毕{0},count:{1}", destFilePath, dataTable.Rows.Count));
        }
    }
}
